define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        {checkbox: true},

                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'group.name', title: __('Group')},
                        {field: 'merchant.username', title: __('Merchant_id')},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        // {field: 'account', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},

                        {
                            field: 'account', title: __('Username'), operate: 'LIKE',
                            align: 'left',
                            formatter:function(value,row, index){
                                return   '<div>' +
                                    "<span style='font-size: 12px;'> " + '登录邮箱:' + row.email + " </span> <br/>" +
                                    "<span style='font-size: 12px;'> " + '登录账号:' + row.account + " </span> <br/>" +
                                    // "<span style='font-size: 12px;'> " + '会员昵称:' + row.nickname + " </span> <br/>" +
                                    '<div>' ;
                            },
                            cellStyle:{
                                css:{
                                    "white-space":"nowrap",     //单行省略必备
                                    "text-overflow":"ellipsis", //单行省略必备
                                    "overflow":"hidden",        //单行省略必备
                                    // "color":"#4E73DF",
                                    "max-width":"210px",
                                }
                            }},


                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        // {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'),  formatter: Table.api.formatter.label, searchList: {1: __('Male'), 0: __('FeMale')}},

                        {field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
                        {field: 'lvl.title', title: __('等级名称'), operate: false},
                        // {field: 'remark', title: __('Remark')},

                        {field: 'money', title: __('Money'), operate: 'BETWEEN', sortable: true},
                        {field: 'score', title: __('Score'), operate: 'BETWEEN', sortable: true},
                        {field: 'render', title: __('Render'), operate: 'BETWEEN', sortable: true},

                        // {field: 'go_status', title: __('GoStatus'), formatter: Table.api.formatter.status, searchList: {normal: __('OnLine'), hidden: __('OffLine')}},
                        {field: 'verification', title: __('GoStatus'), formatter: Table.api.formatter.status, searchList: {normal: __('OnLine'), hidden: __('OffLine'),default:__('default')}},
                        {field: 'is_recommend', title: __('是否推荐'), formatter: Controller.api.formatter.custom, searchList:  {"0": __('不推荐'),"1": __('推荐') } },

                        {
                            field: 'score', title: __('会员统计'), sortable: false,
                            align: 'left',
                            formatter:function(value,row, index){
                              return   '<div>' +
                                 // "<span style='font-size: 13px;color:#409eff;'> " + '收藏数 : ' + row.count.user_fans_count + " </span> <br/>" +
                                 "<span style='font-size: 13px;color:#409eff;'> " + '关注数 : ' + row.count.user_follow_count + " </span> <br/>" +
                                 "<span style='font-size: 13px;color:#409eff;'> " + '动态数 : ' + row.count.user_trends_count + "</span> <br/>"  +
                                 "<span style='font-size: 13px;color:#409eff;'> " + '收藏数 : ' + row.count.user_collect_count + "</span> <br/>"  +
                                 '<div>' ;
                            },
                                cellStyle:{
                                    css:{
                                        "white-space":"nowrap",     //单行省略必备
                                        "text-overflow":"ellipsis", //单行省略必备
                                        "overflow":"hidden",        //单行省略必备
                                        "color":"#4E73DF",
                                        "max-width":"200px",
                                    }
                                }
                            },

                        // {field: 'is_comment_txt', title: __('隐私设置-评论设置'), operate: false,formatter: Table.api.formatter.label},
                        // {field: 'is_give_txt', title: __('隐私设置-点赞设置'), operate: false,formatter: Table.api.formatter.label},
                        // {field: 'is_collect_txt', title: __('隐私设置-收藏设置'), operate: false,formatter: Table.api.formatter.label},

                        {
                            field: 'is_comment', title: __('隐私设置'), sortable: false,
                            align: 'left',
                            formatter:function(value,row, index){
                                return   '<div>' +
                                    "<span style='font-size: 12px;color:#2F9649;'> " + '是否设置评论 : ' + row.is_comment_txt + " </span> <br/>" +
                                    "<span style='font-size: 12px;color:#FF6FBC;'> " + '是否设置点赞 : ' + row.is_give_txt + " </span> <br/>" +
                                    "<span style='font-size: 12px;color:#18bc9c;'> " + '是否设置收藏 : ' + row.is_collect_txt + "</span> <br/>"  +
                                    '<div>' ;
                            },
                            cellStyle:{
                                css:{
                                    "white-space":"nowrap",     //单行省略必备
                                    "text-overflow":"ellipsis", //单行省略必备
                                    "overflow":"hidden",        //单行省略必备
                                    "color":"#4E73DF",
                                    // "max-width":"320px",
                                }
                            }
                        },

                        {
                            field: 'is_speak_me', title: __('通知设置'), sortable: false,
                            align: 'left',
                            formatter:function(value,row, index){
                                return   '<div>' +
                                    "<span style='font-size: 12px;color:#2F9649;'> " + '提到我的 : ' + row.is_speak_me_txt + " </span> <br/>" +
                                    "<span style='font-size: 12px;color:#FF6FBC;'> " + '评   论 : ' + row.is_comment_me_txt + " </span> <br/>" +
                                    "<span style='font-size: 12px;color:#18bc9c;'> " + '私   信 : ' + row.is_private_txt + "</span> <br/>"  +
                                    // "<span style='font-size: 11px;color:#18bc9c;'> " + '邮件提醒 : ' + row.is_mail_txt + "</span> <br/>"  +
                                    '<div>' ;
                            },
                            cellStyle:{
                                css:{
                                    "white-space":"nowrap",     //单行省略必备
                                    "text-overflow":"ellipsis", //单行省略必备
                                    "overflow":"hidden",        //单行省略必备
                                    "color":"#4E73DF",
                                    // "max-width":"320px",
                                }
                            }
                        },

                        // {
                        //     field: 'tags',
                        //     title: __('Tags'),
                        //     searchList: '',
                        //     align: 'left',
                        //     formatter: function (value, row, index) {
                        //         return Table.api.formatter.flag.call(row.tags, row.tags, row, index);
                        //     },
                        //     operate: false,
                        // },
                        {field: 'login_count', title: __('login_count'), operate: 'BETWEEN', sortable: true},
                        {field: 'expire_time', title: __('expire_time'), operate: 'BETWEEN', sortable: true},
                        {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
                        {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},

                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},

                        {field: 'is_examine', title: __('审核'), formatter: Table.api.formatter.status, searchList: {0: __('审核通过'), 1: __('审核关闭')}},

                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'addtabs',
                                    text: __('联系人'),
                                    title: __('联系人'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-align-justify',
                                    url: 'user/user/friend',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                {
                                    name: 'addtabs',
                                    text: __('余额变更记录'),
                                    title: __('余额变更记录'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-align-justify',
                                    url: 'user/user/getUserLog',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                {
                                    name: 'addtabs',
                                    text: __('收到的礼物'),
                                    title: __('收到的礼物'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-align-justify',
                                    url: 'user/user/getGiftLog',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                {
                                    name: 'addtabs',
                                    title: __('关注会员'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa fa-heart',
                                    url: 'user/user/getUserFollow',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                // {
                                //     name: 'addtabs',
                                //     title: __('点赞会员'),
                                //     classname: 'btn btn-xs btn-warning btn-addtabs',
                                //     icon: 'fa fa-thumbs-o-up',
                                //     url: 'user/user/getGive',
                                //     callback: function (data, ret) {
                                //         Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                //     },
                                //     visible:function (){
                                //         return true;
                                //     },
                                // },

                                {
                                    name: 'addtabs',
                                    title: __('会员充值记录'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa fa-yen',
                                    url: 'user/user/getRechargeLog',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                {
                                    name: 'addtabs',
                                    title: __('会员动态点赞'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-thumbs-o-up',
                                    url: 'user/user/getTrends',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                {
                                    name: 'addtabs',
                                    title: __('会员相册'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-file-photo-o',
                                    url: 'user/user/getUserPhoto',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },

                                {
                                    name: 'addtabs',
                                    title: __('会员黑名单'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa fa-bomb',
                                    url: 'user/user/getBlackList',
                                    callback: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    },
                                    visible:function (){
                                        return true;
                                    },
                                },


                            ]

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                custom: function (value, row, index) {
                    //添加上btn-change可以自定义请求的URL进行数据处理
                    return '<a class="btn-change text-success" ' +
                        'data-url="user/user/recommend" data-confirm="确认切换状态？" data-id="' + row.id + '">' +

                        '<i class="fa ' + (row.is_recommend == '1' ? 'fa-toggle-on' : 'fa-toggle-on fa-flip-horizontal text-gray') + ' fa-2x"> </i>' +
                        '</a>';
                },
            },
        }
    };
    return Controller;
});